Reef Language

A systems language that pairs Oberon’s Active Objects with the expressiveness of Ruby and Crystal — compiled to native code, from userland to bare metal.

Overview

Reef is a statically-typed systems programming language that combines three things which rarely appear together: the Active Object concurrency model from Oberon, the expressiveness of languages like Ruby and Crystal, and native compilation that runs anywhere from userland to bare metal.

Active Objects come from A2 Oberon and two decades of research at ETH Zürich. Each Active Object owns its state and guards it with a lock, so concurrent access is synchronized by the language rather than by programmer discipline — exclusive methods take the write lock and are mutually exclusive; shared methods take a reader lock and may run concurrently, and the compiler rejects any attempt to mutate the object’s state from a shared method. The result is data-race freedom for Active Object state, enforced at compile time. An Active Object that declares run() also gets its own background thread.

The syntax is built for people, not for parsers: end-based blocks, string interpolation, pattern matching with guards, generics, sum types, and traits. Reef compiles to C and then to native code through GCC or Clang, with no VM and no runtime dependency — the same toolchain path, and the same optimizer, that C code takes.

Current Status: Active Development — a research project with a working compiler, runtime, and standard library. Reef is pre-1.0: the language is stable enough to build real systems in, and we are still changing it.

Core Strengths

Active Objects

Language-level safe concurrency. Each object owns its state and guards it with a lock — exclusive methods take the write lock and are mutually exclusive, shared methods take a reader lock and run concurrently. The compiler rejects state mutation from a shared method, giving data-race freedom for Active Object state, enforced at compile time. Objects declaring run() get their own background thread.

Modern Type System

Generics with monomorphization, sum types, pattern matching with exhaustiveness checking, traits, and closures with escape analysis.

Clean Syntax

End-based blocks, Ruby/Crystal-like elegance, string interpolation, pattern matching with guards, and default parameters.

Systems Performance

Native compilation via C backend. Supports inline assembly for AMD64, ARM64, and RISC-V. Baremetal compilation for OS development.

Examples

Real programs, compiled and run against Reef v0.7.7. Pick one to see its source and the actual terminal session it produced.

Concurrent hasher

Concurrency

Worker Active Objects with their own threads, no locks in user code.

Source

// parallel_hash.reef - Concurrent file checksums with Active Objects
// Demonstrates: worker AOs with run() threads, await-gated queues,
//               io.dir, io.file, crypto.sha256, sys.args
//
// Usage:
//   parallel_hash <directory>
//
// Hashes every regular file directly inside <directory> with SHA-256.
// Work is spread across 4 worker Active Objects, each with its own
// thread; a collector Active Object aggregates results; main prints
// them sorted by filename, sha256sum-style.

import sys.args as args
import io.dir as dir
import io.file as file
import crypto.sha256 as sha256
import core.result as result
import core.str as str

active object Collector
    names: [string]
    digests: [string]
    count: int
    target: int

    init()
        self.names = new [string](0)
        self.digests = new [string](0)
        self.count = 0
        self.target = 0
    end init

    exclusive proc add(name: string, digest: string)
        self.names = self.names.append(name)
        self.digests = self.digests.append(digest)
        self.count = self.count + 1
    end add

    // Blocks until every dispatched file is hashed. self.target holds
    // the parameter: await conditions only close over self, not locals.
    exclusive proc wait_for(expected: int)
        self.target = expected
        await self.count == self.target
    end wait_for

    exclusive fn digest_for(name: string): string
        mut i = 0
        while i < self.count
            if str.equals(self.names[i], name)
                return self.digests[i]
            end if
            i = i + 1
        end while
        return "?"
    end digest_for
end Collector

active object Worker
    queue: [string]
    done: bool
    sink: Collector

    init(sink: Collector)
        self.queue = new [string](0)
        self.done = false
        self.sink = sink
    end init

    exclusive proc submit(path: string)
        self.queue = self.queue.append(path)
    end submit

    exclusive proc finish()
        self.done = true
    end finish

    // Blocks until a path is queued or finish() was called; "" means
    // done-and-drained. The await lives here, not in run() directly,
    // and run() reaches it via a (legal) exclusive self-call.
    exclusive fn take(): string
        await self.queue.length() > 0 or self.done
        if self.queue.length() == 0
            return ""
        end if
        let path = self.queue[0]
        self.queue = self.queue.remove(0)
        return path
    end take

    run()
        loop
            let path: string = self.take()
            if str.equals(path, "")
                break
            end if
            let contents_r = file.readBinaryFile(path)
            if result.is_ok(contents_r)
                self.sink.add(path, sha256.sha256_bytes(result.unwrap_ok(contents_r)))
            else
                self.sink.add(path, "(unreadable)")
            end if
        end loop
    end run
end Worker

// Selection sort using only append/remove (Reef arrays have no insert).
fn sorted(items: [string]): [string]
    mut remaining: [string] = items
    mut out: [string] = new [string](0)
    while remaining.length() > 0
        mut min_i = 0
        mut i = 1
        while i < remaining.length()
            if str.compare(remaining[i], remaining[min_i]) < 0
                min_i = i
            end if
            i = i + 1
        end while
        out = out.append(remaining[min_i])
        remaining = remaining.remove(min_i)
    end while
    return out
end sorted

proc main()
    if args.count() < 2
        println("Usage: parallel_hash <directory>")
        println("Hashes every regular file in <directory> with SHA-256,")
        println("spread across 4 concurrent worker Active Objects.")
        return
    end if
    let root = args.get(1)
    let listing_r = dir.list_dir(root)
    if result.is_err(listing_r)
        println("parallel_hash: cannot read directory: ${root}")
        return
    end if

    // Keep regular files only.
    mut files: [string] = new [string](0)
    let entries = result.unwrap_ok(listing_r)
    for entry in entries
        let path = root + "/" + entry
        if not dir.is_directory(path)
            files = files.append(path)
        end if
    end for

    let collector = new Collector()
    let workers = [new Worker(collector), new Worker(collector),
                   new Worker(collector), new Worker(collector)]
    mut i = 0
    for path in files
        workers[i % 4].submit(path)
        i = i + 1
    end for
    for w in workers
        w.finish()
    end for
    collector.wait_for(files.length())

    let ordered = sorted(files)
    for path in ordered
        println("${collector.digest_for(path)}  ${path}")
    end for
end main

Build, run & output

$ reefc parallel_hash.reef -o ph
$ ./ph examples/baremetal_kernel
e738b7045a8b75e7c8329e3482bcfdca176f214768ddac0178923be48b55a5a4  examples/baremetal_kernel/Makefile.limine
365b478f8a0687cba475735f22137e9356b191ecc1b5cd9c595310379448941c  examples/baremetal_kernel/Makefile.limine-aarch64
717febe9c7d9ea5bc8287d098911ee4b2c95417038d4055498aff1bcdc390665  examples/baremetal_kernel/Makefile.limine-riscv64
3647fdbb482bacba9e0f1f9243af4c80c41c5b3c52fe28005d53fb89eed5c1db  examples/baremetal_kernel/README.md
a0bdea5adfb0b8ce592b8a0a456504669ec5ac92a4f4606ee52d57c14c4161a0  examples/baremetal_kernel/boot.S
c997eb3f1153b3ccf5c083e48b59ccc21e631b52c6e200eb7e9969a234215d75  examples/baremetal_kernel/boot.asm
756f440fbb79e9b916f9ddc8504d8245cf02385fb31450ebe63e800c61a4dbb7  examples/baremetal_kernel/kernel.ld
9c304a4101cc86c7a39fbb38a80a4217d8ef45dac5ca0546b0053d07d1d1a5b5  examples/baremetal_kernel/kernel.reef
6792c31a09336dbec90638b84e3e8e9cfb61f74ca87d74780e6e29b7c47e33ac  examples/baremetal_kernel/kernel_limine.reef
f83d3fff85ac85c2a81327b0f8c467d5b7284dc18befbef78de3eb5d1c2e33c5  examples/baremetal_kernel/kernel_limine_aarch64.reef
aa0ceed7c087a6cbd60e2ddf9bf419985aa0f6a8e0e9fed6a4a80a9bfa47ed6a  examples/baremetal_kernel/kernel_limine_riscv64.reef
20a9c5187f390ba5c0ce7dcedf7e5ed1036fdb63b802dc4e67ee44fc6f522c2b  examples/baremetal_kernel/limine_boot.c
b976685eb0c13fed7c41194e57d1f602120ee659c4a8585541d9ada0ffd00756  examples/baremetal_kernel/limine_boot_aarch64.c
42bb1dadc78fb62dbb5c0ebdcf0106d8130565b315ab498197f1077007801692  examples/baremetal_kernel/limine_boot_riscv64.c
75ecd597a3eb7d566ca7a7abba451fd90e72f2f13cb5e618d7d6849e897a5e0c  examples/baremetal_kernel/limine_kernel.ld
3f7a5e11e615273890a2bd8bc43884b04aefab83fe80604a771eee15fe4fd7d6  examples/baremetal_kernel/limine_kernel_aarch64.ld
fa4815277fa66cf090e66c453c3db75a49abefa227d754fb72cdfdf768f30fb6  examples/baremetal_kernel/limine_kernel_riscv64.ld
018af5c30d0127556ae137306e9c2e38e2d21544d5ae45c3c64ba01cf2284e79  examples/baremetal_kernel/platform.c

Technical Details

Compilation

Lexer, parser, type checker, and code generator produce readable C code. GCC/Clang compiles to native executables.

Runtime

Written in C99, with no dependency on a VM or language runtime beyond it. Mark-and-sweep garbage collector with concurrent marking and lazy sweeping: application threads keep running while the collector marks. Precise stack scanning via a shadow-frame chain — the collector knows exactly which slots hold pointers rather than guessing conservatively.

Standard Library

20 packages, 138 modules: collections, I/O and filesystem, text processing, encoding (JSON, YAML, TOML, CSV, MessagePack, base64), hashing (SHA-256, SHA-1, MD5, HMAC, CRC32), compression (gzip, zlib, zip, lz4), and networking (TCP, UDP, Unix sockets, DNS, HTTP, TLS).

OS Development

reef-os library for kernel programming. CPU primitives, serial drivers, spinlocks, and Limine bootloader support.

License & Availability

Reef is open source under the Apache License 2.0 with the LLVM runtime library exception (Apache-2.0 WITH LLVM-exception).

The runtime library exception means programs you compile with Reef carry no attribution obligation from the portions of the Reef runtime embedded in your binary, and Reef code may be combined with GPLv2 software. Apache-2.0 includes an explicit patent grant.

No contributor license agreement is required. Apache-2.0 §5 places contributions under the same terms as the rest of the project.

Reef is developed by Leafscale, LLC. Because it is Apache-2.0 licensed, anyone can fork, build on, and continue it independently of us.

  • Current release: v0.7.7
  • Platforms: Linux, macOS, FreeBSD, OpenBSD, NetBSD, illumos

Target Use Cases

  • Concurrent Systems - Web servers, message brokers, pipeline and worker systems
  • Systems Programming - Operating system kernels, device drivers, embedded systems
  • High-Performance Computing - Parallel processing, data stream processing
  • Research and Language Design - A working testbed for Active Object concurrency on real hardware