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 written in raz, about 10,700 lines, and builds itself. It makes x86-64 machine code and the ELF file itself, with no assembler or linker, in one pass, at about 500,000 lines a second.
A taste
(* 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.
- Strings of UTF-8 bytes, raw strings over lines that keep the code's indent, and
matchon a string. - 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,
ERRORvalues anddefer, in place of exceptions. - Modules with bodies, and generic modules:
Map(K, V; hash, eq). ^VOLATILE Tand the atomicsCAS,XCHG,XADD,FENCE, for devices and lock-free code.externprocedures and variables from C, code procedures in assembly, andSYSCALL.- Threads without C, a library of
Out,Str,Bytes,Fmt,Map,Sortand 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. Its second volume describes the library. Both are on one page, and each is a PDF: the language (36 pages) and the library.
Download
raz 0.25.3 is a tarball for x86-64 Linux with the compiler, raz,
its library, lib/, which it finds beside itself, the formatter
and the documentation tool as sources in tools/, and the manual
pages. It needs nothing else installed.
$ tar xzf raz-0.25.3-linux-x86_64.tar.gz
$ ln -s $PWD/raz-0.25.3-linux-x86_64/raz ~/.local/bin/raz
$ raz run Hello.raz
The link works since raz finds lib/ beside its real path. The
manual pages are in man/: man ./man/raz-tutorial.7.
The address download/latest always leads to the newest release,
and download/raz-0.25.3-linux-x86_64.tar.gz to this one, for
good. Earlier releases: 0.25.2, 0.25.1, 0.25.0, 0.24.0, 0.23.0, 0.22.0, 0.21.0, 0.20.0, 0.19.0, 0.18.1, 0.18.0, 0.17.2, 0.17.1, 0.17.0, 0.16.0, 0.15.0, 0.14.0, 0.13.0, 0.12.0, 0.11.1, 0.11.0, 0.10.1, 0.10.0, 0.9.1, 0.9.0, 0.8.0, 0.7.1; each has its SHA-256 beside it, with
.sha256 added to its name.
SHA-256 45fdafd83e889baff969b5923d48d5a6793ce1d0b337e087f00d47939c279101
Release pages give each
version's commit, notes, compiler and source archives, with checksums.
Browse the source and history, or clone:
git clone https://raz.lucela.org/source/.