raz

A small systems language in Wirth’s tradition, for x86-64 Linux. Raz is Polish for one, as in counting.

A raz program can lay a record over a device’s registers, read and write memory exactly as written, take part in lock-free algorithms, make system calls and call C libraries. It has no garbage collector and no hidden run time: what the program does is what its text says.

The compiler is one Free Pascal program of about 7,800 lines. It makes x86-64 machine code and the ELF file itself, with no assembler or linker, in one pass, at about a million lines a second.

~7,800 lines of compiler ~1M lines compiled a second static executables, no run time to install 1 report, ~2,000 lines

A taste

Taste.raz
(* Several results, slices, and checks that say what failed. *)
module Taste;
import Out;

proc divmod(a, b: INT): (INT, INT);
begin
    return a div b, a mod b;
end;

proc sum(s: []INT): INT;
var i, t: INT;
begin
    for i := 0 to LEN(s) - 1 do t := t + s[i]; end;
    return t;
end;

proc main*;
var q, r: INT; a: [5]INT; i: INT;
begin
    for i := 0 to 4 do a[i] := i * i; end;
    q, r := divmod(sum(a), 7);
    Out.int(q); Out.str(" remainder "); Out.int(r); Out.ln;
    Out.int(sum(a[1..3])); Out.ln;
end;

end Taste.
4 remainder 2
5

What it has

  • Integers of 8 to 64 bits, signed and unsigned, which wrap; BOOL, F32, F64. Nothing converts unless it is written.
  • Arrays, checked slices, pointers, records laid out as C lays them out, packed records, enumerations, sets, and variants with match.
  • Every index and slice is checked; a failure says where it was, with the values, and the calls under way.
  • Every variable starts at zero. Behaviour is defined everywhere but through pointers.
  • No garbage collector: memory comes from an allocator the program chooses and passes.
  • Several results, ERROR values and defer, in place of exceptions.
  • Modules with bodies, and generic modules: Map(K, V; hash, eq).
  • ^VOLATILE T and the atomics CAS, XCHG, XADD, FENCE, for devices and lock-free code.
  • extern procedures and variables from C, code procedures in assembly, and SYSCALL.
  • Threads without C, a library of Out, Str, Fmt, Map, Sort and more, and gdb that knows your lines.
  • A formatter, a documentation tool, and editor support for vim and emacs.

Learn it

Raz, Set, Go is a tour of the language in 15 lessons, each with programs you can run. More Raz is the second tour: the library, programs with no run time, procedures in assembly, system calls, volatile accesses, atomics and lock-free code, in 18 more.

The language, in writing

The language is defined by the report, which is short on purpose: whatever it doesn’t allow, raz doesn’t have. There is also a guide to reading the compiler, file by file.

Download

Each release is a tarball with the compiler, raz, and its library, lib/, which it finds beside itself.

Latest release Source on GitHub
$ tar xzf raz-*.tar.gz
$ ./raz run examples/Hello.raz
hello, world

To build it yourself you need Free Pascal 3.2.2:

$ apt-get install fp-compiler
$ git clone https://github.com/ldiaz94/raz
$ cd raz && make && make install    # ~/.local, or PREFIX=/usr/local