Oberon 07z

A whole language you can hold in your head.

Oberon 07z is Niklaus Wirth's Oberon-07 as a systems language: compiled to native code, with no garbage collector, and with the few things today's programs need: 64-bit integers, UTF-8 text, module paths, cleanup with DEFER, and calls into C.

Main.obEdit.Store System.Close
MODULE Main;
IMPORT R := IO.Reader, Hexdump;
PROCEDURE main(): INTEGER;
VAR r: R.Reader;
BEGIN R.StandardInput(r); RETURN Hexdump.Dump(r, TRUE) END main;
END Main.
A complete program: it hex-dumps whatever arrives on standard input.

Why Oberon

Small, checked and native.

  1. 01

    Small

    Wirth defined Oberon-07 in one short report: modules, procedures, records, arrays and pointers, and very little else. There's one way to write most things, so code reads the same to everyone who knows the language.

  2. 02

    Checked

    Array indexes are checked. Integer arithmetic stops on overflow instead of wrapping, and new storage starts zeroed. Arenas give dynamic bytes an explicit lifetime, and refuse a block once its arena is released.

  3. 03

    Native

    The compiler builds standalone executables through LLVM, for Linux on x86-64. There's no garbage collector: memory comes from NEW and goes back with FREE, and a program can link a C object and call into it like any other procedure.

What 07z adds

The Report's language, plus five things you'd miss.

64-bit integers

LONGINT sits beside the Report's INTEGER, for the values that need 64 bits.

value := LONG(-42)

UTF-8 text

Source and text are UTF-8. Positions count characters, so the fourth character of "café" is é.

Text.CharAt("café", 3, ch)

Module paths

Modules nest under dotted names, and an import can take a short alias.

IMPORT R := IO.Reader, Console := IO.Console;

Cleanup with DEFER

Register the cleanup next to the thing it cleans up. It runs when the procedure returns.

Main.ob
PROCEDURE DumpOpened(VAR r: R.Reader): INTEGER;
BEGIN DEFER R.Close(r); RETURN Hexdump.Dump(r, FALSE) END DumpOpened;

Calls into C

Declare a C function and call it like any procedure. The standard library's console is written this way.

IO/Console.ob
MODULE IO.Console;
EXTERN "C" PROCEDURE obHostStdout(src: ARRAY OF BYTE; at: INTEGER; count: INTEGER): INTEGER;
EXTERN "C" PROCEDURE obHostStderr(src: ARRAY OF BYTE; at: INTEGER; count: INTEGER): INTEGER;

The library

Explicit about who owns every byte.

Every module works on storage the caller owns, or on an arena the caller chose. Failures come back as named statuses, and each operation says what a failure leaves untouched.

Arena
Bounded byte storage with an explicit lifetime, released all at once.
Buf
A byte buffer with a fixed capacity. An append that won't fit changes nothing.
Binary
Big-endian 16- and 32-bit integers, read and written on bounded cursors.
Text
Length, indexing, search, trimming and joining, on text the caller owns.
IO.Reader
One reader for standard input, files and memory.
IO.Console
Standard output and error, with complete writes.
IO.Files
Files and directories: create, read, write, rename, delete and list.
IO.Lines
Lines from a buffer or a reader, even when CRLF splits across reads.
IO.Fmt
Decimal and hex output, with width and padding.
Parse
Integers from text, with the position and the reason when they don't parse.
Net.TCP
TCP connections: connect, read, write and close.
Time
The wall clock, in UTC milliseconds.
Args
The program's command-line arguments.

Get Oberon 07z

Your program is a package.

An Oberon 07z program is a Gritpack package. Its manifest names the dialect, and the standard library, TOML and HTTP come in as ordinary dependencies: oberon07z-stdlib, oberon07z-toml and oberon07z-http.

Write to info@frogfish.io, and we'll set you up.

gritpack.toml
[package]
name = "hello"
version = "0.1.0"
dialect = "oberon/07z"
encoding = "source/utf8"
files = ["src/**"]

[dependencies]
oberon07z-stdlib = "0.1.0"